import json
from datetime import datetime


class JSONEncoderDate(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime.datetime):
            return obj.strftime("%Y-%m-%d %H:%M:%S")
        else:
            return json.JSONEncoder.default(self, obj)

def to_json(obj):
    print(obj)
    dict = obj
    if hasattr(obj,'__dict__'):
            dict=obj.__dict__
    return json.dumps(dict, ensure_ascii=False, cls=JSONEncoderDate)